package io.gimo.study.design_pattern.factory.abstract_factory.product;


import io.gimo.study.design_pattern.factory.abstract_factory.Sortor;

import java.util.Arrays;

public class ShellSortor implements Sortor {

    @Override
    public void sort(int[] target) {
        int d = target.length;
        while (true) {
            d = d / 2;
            for (int x = 0; x < d; x++) {
                for (int i = x + d; i < target.length; i = i + d) {
                    int temp = target[i];
                    int j;
                    for (j = i - d; j >= 0 && target[j] > temp; j = j - d) {
                        target[j + d] = target[j];
                    }
                    target[j + d] = temp;
                }
            }
            if (d == 1)
                break;
        }
        System.out.println(Arrays.toString(target));
    }

}
